﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RibbonControler
{
    public partial class ColorPicker : Form
    {
        Bitmap HSLbitmap;

        public ColorPicker()
        {
            InitializeComponent();
            createHSLBitmap();
        }

        void createHSLBitmap()
        {
            int picBoxWidth = pictureBox1.Size.Width;
            int picBoxHeight = pictureBox1.Size.Height;
            int halfWidth = pictureBox1.Size.Width / 2;
            int halfHeight = pictureBox1.Size.Height / 2;

            HSLbitmap = new Bitmap(picBoxWidth, picBoxHeight);

            HSLColor color = new HSLColor();
            color.Saturation = 240;

            for (int i = 0; i < 480; i++)
            {
                for (int j = 0; j < 480; j++)
                {
                    color.Hue = j / 480.0;
                    color.Luminosity = i / 480.0;
                    HSLbitmap.SetPixel(i, j, (Color)color);
                }
            }

            pictureBox1.BackgroundImage = HSLbitmap;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                int x = e.X;
                int y = e.Y;
                if (e.X < 0)
                    x = 0;
                if (e.Y < 0)
                    y = 0;
                if (e.X > pictureBox1.Width)
                    x = pictureBox1.Width;
                if (e.Y > pictureBox1.Height)
                    y = pictureBox1.Height;

                try
                {
                    Color c = HSLbitmap.GetPixel(x, y);

                    panel2.BackColor = c;
                }
                catch
                {
                }

            }
        }
    }
}
